import json
import os
# 将类对象，转化成json
class json_obj(object):
    def __init__(self,configuration={},connectionName='newhope_data_dev',content='',currentDatabase='fdc_dc',description='',directory='',name='',templateVersion='1.0',type='DWSSQL'):
      self.configuration = configuration
      self.connectionName=connectionName
      self.content=content
      self.currentDatabase=currentDatabase
      self.description=description
      self.directory=directory
      self.name=name
      self.templateVersion=templateVersion
      self.type=type

if __name__ == '__main__':
    paths=os.path.join(os.path.dirname(__file__),'output')
    out_paths=os.path.join(os.path.dirname(__file__),'script')
    files=os.listdir(path=paths)
    out_file=str()
    for file in files:
      obj=json_obj()
      file_name=file.split('.sql')[0]
      file_path=os.path.join(paths,file)
      out_file_path=os.path.join(out_paths,file_name.strip().lower()+'.script')
      obj.name=file_name
      with open(file=file_path,mode='r',encoding='utf-8') as rf:
          lines=rf.readlines()
          obj.content=''.join(lines)
      with open(file=out_file_path,mode='w',encoding='utf-8') as wf:
        wf.write(json.dumps(obj.__dict__,ensure_ascii=False))

